var app = require('../../utils/util.js');
import {password} from '../../utils/request/apiurl'
import api from '../../utils/request/api'

var app = require('../../utils/util.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
	processData: [{
	      name: '验证手机号',
	      start: '../../asset/images/now01@2x.png',
	      end: '../../asset/images/yellow01@2x.png',
	      icon: '../../asset/images/yellow01@2x.png'
	    },
	    {
	      name: '更换新密码',
	      start: '../../asset/images/now02@2x.png',
	      end: '../../asset/images/yellow02@2x.png',
	      icon: '../../asset/images/now02@2x.png'
	    },
	    {
	      name: '更换成功',
	      start: '../../asset/images/now03@2x.png',
	      end: '../../asset/images/yellow03@2x.png',
	      icon: '../../asset/images/gray03@2x.png'
	    }],
	uid:'',
   password:'',//旧密码
   newPassWord:'',//支付密码
   ispassword:'',//再次输入支付密码
  },
  //获取input输入框的值
  // 请输入密码
  getPhoneValue:function(e){
    this.setData({
      newPassWord:e.detail.value
    })
  },
  // 再次请输入
  getCodeValues: function (e) {
    this.setData({
      ispassword: e.detail.value
    })
  },
  getCode:function(){
    // var a = this.data.phone;
    // var _this = this;
    var myreg = /^\d{6}$/;
    // console.log(this.data.newPassWord, this.data.ispassword)
    if (this.data.newPassWord == ""&&this.data.ispassword=='') {
      wx.showToast({
        title: '密码不能为空',
        icon: 'none',
        duration: 2000
      })
      return false;
    } else if (!myreg.test(this.data.newPassWord)&&!myreg.test(this.data.ispassword)) {
      wx.showToast({
        title: '请输入正确的密码',
        icon: 'none',
        duration: 2000
      })
      return false;
    }else if (this.data.newPassWord !=this.data.ispassword) {
      wx.showToast({
        title: '两次密码输入不一样',
        icon: 'none',
        duration: 2000
      })
      return false;
    }else{
      var source={
      	uid:this.data.uid,
      	password:this.data.newPassWord,     
      }
      // console.log(source)
      api.post(password.PayPassword,source).then(res => {
		// console.log(res)
		// debugger
		if(res=='OK'){
			// wx.showToast({
			// 	title: '修改成功',
			// 	icon: 'none',
			// 	duration: 2000
			// })
			// wx.redirectTo({
			//   url: '../change-numdone/change-numdone',
			// })//页面跳转
			wx.showToast({
			    title: '修改成功',
			    icon: 'none',
			    success: function () {
			      setTimeout(function() {
			        wx.redirectTo({
			          url: '../change-numdone/change-numdone',
			        })//页面跳转
			      }, 1000);
			    }
			});			
		}		
      }).catch(err => {
      	// console.log(err)
      	wx.showToast({
      		title: err.message,
      		icon: 'none'
      	})
      })
      
    }  
  },
  //提交表单信息
  save:function(){
	this.getCode()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var userInfo = wx.getStorageSync('userInfo');
    if (userInfo.rank) {
    	this.setData({
    		uid: userInfo.uid,
    	})
    }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
	wx.showNavigationBarLoading() //在标题栏中显示加载
	this.onLoad()
	setTimeout(function() {
		wx.hideNavigationBarLoading() //完成停止加载
		wx.stopPullDownRefresh() //停止下拉刷新
	}, 1500);
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  //进度条的状态
    setPeocessIcon: function () {
      var index = 0//记录状态为1的最后的位置
      var processArr = this.data.processData
      // console.log("progress", this.data.detailData.progress)
      for (var i = 0; i < this.data.detailData.progress.length; i++) {
        var item = this.data.detailData.progress[i]
        processArr[i].name = item.word
        if (item.state == 1) {
          index = i
          processArr[i].icon = "../../img/process_3.png"
          processArr[i].start = "#45B2FE"
          processArr[i].end = "#45B2FE"
        } else {
          processArr[i].icon = "../../img/process_1.png"
          processArr[i].start = "#EFF3F6"
          processArr[i].end = "#EFF3F6"
        }
      }
      processArr[index].icon = "../../img/process_2.png"
      processArr[index].end = "#EFF3F6"
      processArr[0].start = "#fff"
      processArr[this.data.detailData.progress.length - 1].end = "#fff"
      this.setData({
        processData: processArr
      })
    },
})